home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / demos / misc / gettintired.dms / in.adf / Source / init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-14  |  4.5 KB  |  174 lines

  1. /* Main program initialization */
  2.  
  3. #include "includes.prl"
  4.  
  5. #include "common.h"
  6. #include "protos.h"
  7.  
  8. /***** Static function declarations *****/
  9.  
  10. static void init_conerr(UBYTE *str);
  11.  
  12. /***** External variables *****/
  13.  
  14. /* Library pointers */
  15. extern struct ExecBase *SysBase;
  16. extern struct DosLibrary *DOSBase;
  17. struct GfxBase *GfxBase;
  18. struct IntuitionBase *IntuitionBase;
  19. struct Library *DiskfontBase;
  20. struct Library *PTReplayBase;
  21.  
  22. PLANEPTR theRaster, theRaster2;
  23. struct RastPort theRP;
  24. struct RastPort theRP_3bpl;
  25. struct RastPort theRP_2bpl;
  26. struct RastPort theRP_1bpl;
  27. struct BitMap theBitMap;
  28. struct BitMap theBitMap_3bpl;
  29. struct BitMap theBitMap_2bpl;
  30. struct BitMap theBitMap_1bpl;
  31. struct NewScreen theScreen =
  32. {
  33.   0, 0, 320, 256, 4, 0, 1, 0,
  34.   CUSTOMSCREEN | CUSTOMBITMAP | SCREENQUIET, NULL, NULL, NULL, &theBitMap
  35. };
  36. struct Screen *mainScreen;
  37. struct ViewPort *mainVP;
  38. struct TextFont *writerFont;
  39. struct TextAttr writerAttr =
  40. { (STRPTR)"courier.font", 15, 0, 0 };
  41.  
  42. /***** Global functions *****/
  43.  
  44. /* Open all needed global resources */
  45. BOOL init_open_all(void)
  46. {
  47.   PLANEPTR temp;
  48.   UWORD i;
  49.  
  50.   /* Check for at least release 3.0 */
  51.   if (SysBase->LibNode.lib_Version < 33)
  52.   {
  53.     init_conerr((UBYTE *)"This program requires Amiga Kickstart Release 1.2 +\n");
  54.     return (FALSE);
  55.   }
  56.  
  57.   /* Open needed libraries */
  58.   if (!(IntuitionBase = (struct IntuitionBase *)
  59.   OpenLibrary((UBYTE *)"intuition.library", _LIB_VERSION)))
  60.   {
  61.     init_conerr((UBYTE *)"Unable to open intuition.library version 33\n");
  62.     return (FALSE);
  63.   }
  64.   if (!(GfxBase = (struct GfxBase *)
  65.   OpenLibrary((UBYTE *)"graphics.library", _LIB_VERSION)))
  66.   {
  67.     init_conerr((UBYTE *)"Unable to open graphics.library version 33\n");
  68.     return (FALSE);
  69.   }
  70.   if (!(DiskfontBase = OpenLibrary((UBYTE *)"diskfont.library", _LIB_VERSION)))
  71.   {
  72.     init_conerr((UBYTE *)"Unable to open diskfont.library version 33\n");
  73.     return (FALSE);
  74.   }
  75.   if (!(PTReplayBase = OpenLibrary((UBYTE *)"ptreplay.library", 0)))
  76.   {
  77.     init_conerr((UBYTE *)"Unable to open ptreplay.library\n");
  78.     return (FALSE);
  79.   }
  80.  
  81.   InitBitMap(&theBitMap, 4, 384, 256);
  82.   InitBitMap(&theBitMap_3bpl, 3, 384, 256);
  83.   InitBitMap(&theBitMap_2bpl, 2, 384, 256);
  84.   InitBitMap(&theBitMap_1bpl, 1, 384, 256);
  85.  
  86.   if (!(theRaster = AllocRaster(384 * 4, 256)))
  87.   {
  88.     init_conerr((UBYTE *)"Unable to allocate screen memory\n");
  89.     return (FALSE);
  90.   }
  91.   if (!(theRaster2 = AllocRaster(384 * 4, 256)))
  92.   {
  93.     init_conerr((UBYTE *)"Unable to allocate screen memory\n");
  94.     return (FALSE);
  95.   }
  96.   temp = theRaster;
  97.   for (i = 0; i < 4; i ++)
  98.   {
  99.     theBitMap.Planes[i] = temp;
  100.     theBitMap_3bpl.Planes[i] = temp;
  101.     theBitMap_2bpl.Planes[i] = temp;
  102.     theBitMap_1bpl.Planes[i] = temp;
  103.     temp += (48 * 256);
  104.   }
  105.  
  106.   InitRastPort(&theRP);
  107.   InitRastPort(&theRP_3bpl);
  108.   InitRastPort(&theRP_2bpl);
  109.   InitRastPort(&theRP_1bpl);
  110.  
  111.   theRP.BitMap = &theBitMap;
  112.   theRP_3bpl.BitMap = &theBitMap_3bpl;
  113.   theRP_2bpl.BitMap = &theBitMap_2bpl;
  114.   theRP_1bpl.BitMap = &theBitMap_1bpl;
  115.   SetRast(&theRP, 0);
  116.  
  117.   if (!(mainScreen = OpenScreen(&theScreen)))
  118.   {
  119.     init_conerr((UBYTE *)"Unable to open main screen\n");
  120.     return (FALSE);
  121.   }
  122.   mainVP = &mainScreen->ViewPort;
  123.   for (i = 0; i < 16; i ++)
  124.     SetRGB4(&mainScreen->ViewPort, i, 0, 0, 0);
  125.  
  126.   if (!(writerFont = OpenDiskFont(&writerAttr)))
  127.   {
  128.     init_conerr((UBYTE *)"Unable to open writer font\n");
  129.     return (FALSE);
  130.   }
  131.  
  132.   SetFont(&theRP, writerFont);
  133.   SetFont(&theRP_3bpl, writerFont);
  134.   SetFont(&theRP_2bpl, writerFont);
  135.   SetFont(&theRP_1bpl, writerFont);
  136.  
  137.   return (TRUE);
  138. }
  139.  
  140. /* Close all global resources opened */
  141. void init_close_all(void)
  142. {
  143.   if (writerFont) CloseFont(writerFont);
  144.  
  145.   if (mainScreen) CloseScreen(mainScreen);
  146.   if (theRaster2) FreeRaster(theRaster2, 4 * 384, 256);
  147.   if (theRaster) FreeRaster(theRaster, 4 * 384, 256);
  148.  
  149.   /* Close opened libraries */
  150.   if (PTReplayBase) CloseLibrary(PTReplayBase);
  151.   if (DiskfontBase) CloseLibrary(DiskfontBase);
  152.   if (GfxBase) CloseLibrary((struct Library *)GfxBase);
  153.   if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
  154. }
  155.  
  156. /***** Static functions *****/
  157.  
  158. /* Display an error message in a small console window */
  159. static void init_conerr(UBYTE *str)
  160. {
  161.   BPTR fileHandle;        /* Console window filehandle */
  162.  
  163.   /* Open small console window */
  164.   if (!(fileHandle = Open((UBYTE *)"CON:50/50/500/100/Picnic Editor error",
  165.   MODE_OLDFILE)))
  166.     return;
  167.   /* Write message in window */
  168.   Write(fileHandle, str, strlen((char *)str));
  169.   /* Wait for 3 seconds */
  170.   Delay(150);
  171.   /* Close window */
  172.   Close(fileHandle);
  173. }
  174.